package com.hongyuan.sellfitness.ui.home.activity;

import android.os.Bundle;
import android.util.Log;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.sellfitness.BR;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.data.md5.BaseUtil;
import com.hongyuan.sellfitness.databinding.ActivitySelectCouponBinding;
import com.hongyuan.sellfitness.ui.home.view_mode.UseCouponViewModel;

public class UseCouponListActivity extends CustomActivity<ActivitySelectCouponBinding, UseCouponViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_select_coupon;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public UseCouponViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(UseCouponViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();

        setOnRefresh(binding.refresh,REFRESH_0X4);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.clearParams();
        viewModel.clearParams().setParams("coupon_for",getBundle().getString("couponFor"))
                .setParams("total_money",getBundle().getString("totalMoney"));
        if(BaseUtil.isValue(getBundle().getString("os_id"))){
            viewModel.setParams("os_id",getBundle().getString("os_id"));
        }


    }
}
